/**
 *
 * ......................我佛慈悲.......................
 *                       _oo0oo_
 *                      o8888888o
 *                      88" . "88
 *                      (| -_- |)
 *                      0\  =  /0
 *                    ___/`---'\___
 *                  .' \\|     |// '.
 *                 / \\|||  :  |||// \
 *                / _||||| -卍-|||||- \
 *               |   | \\\  -  /// |   |
 *               | \_|  ''\---/''  |_/ |
 *               \  .-\__  '-'  ___/-. /
 *             ___'. .'  /--.--\  `. .'___
 *          ."" '<  `.___\_<|>_/___.' >' "".
 *         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *         \  \ `_.   \_ __\ /__ _/   .-` /  /
 *     =====`-.____`.___ \_____/___.-`___.-'=====
 *                       `=---='
 *
 *..................佛祖开光 ,永无BUG....................
 *         CSDN博客:http://blog.csdn.net/song5347
 *       github地址:https://github.com/lingsuiderongyan
 *             邮箱:lingsuiderongyan@163.com
 */

import UIKit
import SnapKit

class LSStatusRectweetView: UIView {
    
    //记录转发微博视图的地步约束
    var retweetViewBottonConstranint: Constraint?
    
    //MARK: - 使用ViewModel绑定数据
    var statusViewModel: LSStatusViewModel? {
        
        didSet {
            //绑定转发微博内容富文本
            contentLabel.attributedText = statusViewModel?.retweetAttributedString
            
            //卸载上一次约束
            retweetViewBottonConstranint?.uninstall()
            
            //判断配图是否存在并且是否大于0
            if let picUrls = statusViewModel?.status?.retweeted_status?.pic_urls where picUrls.count > 0 {
                
                //显示配图
                pictureView.hidden = false
                //设置配图信息
                pictureView.picUrls = picUrls
                //更新约束
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.retweetViewBottonConstranint = make.bottom.equalTo(pictureView).offset(StatusTableViewCellMargin).constraint
                })
            } else {
                //隐藏配图
                pictureView.hidden = true
                //更新约束
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.retweetViewBottonConstranint = make.bottom.equalTo(contentLabel).offset(StatusTableViewCellMargin).constraint
                })
            }
        }
    }
    
    //MARK: - 懒加载控件
    private lazy var contentLabel: UILabel = {
        
        let label = UILabel(fontSize: StatusFontSize, textColor: UIColor.grayColor())
            //多行显示
        label.numberOfLines = 0
        return label
    }()
    
    //配图视图
    private lazy var pictureView: LSStatusPictureView = {
        
        let view = LSStatusPictureView()
        view.backgroundColor = self.backgroundColor
        return view
        
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 添加控件设置约束
    private func setupUI() {
        
        backgroundColor = UIColor(white: 0.96, alpha: 1)
        
        //添加控件
        addSubview(contentLabel)
        addSubview(pictureView)
        
        //contentLabel.text = "月夜茉莉,月夜茉莉,月夜茉莉"
        
        //设置约束
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(StatusTableViewCellMargin)
            make.leading.equalTo(self).offset(StatusTableViewCellMargin)
            make.trailing.equalTo(self).offset(-StatusTableViewCellMargin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusTableViewCellMargin)
            
        }
        
        //关键约束,让其转发微博的视图底部的约束 = 内容底部的约束 + 间距
        self.snp_makeConstraints { (make) -> Void in
            self.retweetViewBottonConstranint = make.bottom.equalTo(pictureView).offset(StatusTableViewCellMargin).constraint
        }
    }
    

}




















